package com.sakura.mall.coupon.homeSubject.controller;

import com.sakura.mall.common.response.Page;
import com.sakura.mall.common.response.R;
import com.sakura.mall.coupon.homeSubject.domain.request.AddHomeSubjectRequest;
import com.sakura.mall.coupon.homeSubject.domain.request.UpdateHomeSubjectRequest;
import com.sakura.mall.coupon.homeSubject.domain.request.HomeSubjectPageRequest;
import com.sakura.mall.coupon.homeSubject.service.HomeSubjectService;
import com.sakura.mall.coupon.homeSubject.domain.vo.HomeSubjectVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 首页专题表【jd首页下面很多专题，每个专题链接新的页面，展示专题商品信息】
 *
 * @author sakura
 */
@RestController
@RequestMapping("/homeSubject")
@RequiredArgsConstructor
public class HomeSubjectController {

    private final HomeSubjectService homeSubjectService;


    /**
     * 新建
     *
     * @return R {@link Void}
     */
    @PostMapping
    public R<Void> create(@RequestBody @Validated AddHomeSubjectRequest request) {
        homeSubjectService.add(request);
        return R.ok();
    }


    /**
     * 分页获取
     *
     * @return R {@link Page<HomeSubjectVo>}
     */
    @GetMapping("list")
    public R<Page<HomeSubjectVo>> page(HomeSubjectPageRequest request) {
        Page<HomeSubjectVo> ret = homeSubjectService.queryPage(request);
        return R.ok(ret);
    }


    /**
     * 根据id删除
     *
     * @return R {@link Void}
     */
    @DeleteMapping("{id}")
    public R<Void> remove(@PathVariable Long id) {
        homeSubjectService.removeById(id);
        return R.ok();
    }


    /**
     * 根据id更新
     *
     * @return R {@link Void}
     */
    @PostMapping("{id}")
    public R<Void> update(@PathVariable Long id, @RequestBody UpdateHomeSubjectRequest request) {
        homeSubjectService.updateById(id, request);
        return R.ok();
    }

}
